# 设置Django的运行环境
import os
from os.path import abspath, dirname
import sys
import django

basedir = dirname(dirname(abspath(__file__)))
os.chdir(basedir)
sys.path.insert(0, '')
os.environ['DJANGO_SETTINGS_MODULE'] = 'pro1.settings'
django.setup()

from app1.models import Book

books = [
        {'name': 'Python for Unix and Linux System Administration',
         'price': 10,
         'year': 2008,
         'author': 'Noah Gift, Jeremy M. Jones'},
        {'name': 'Beginning Python',
         'price': 15,
         'year': 2010,
         'author': 'James Payne'},
        {'name': 'Python Cookbook, 2nd Edition',
         'price': 25,
         'year': 2005,
         'author': 'Alex Martelli, Anna Ravenscroft, David Ascher'},
        {'name': 'MySQL for Python',
         'price': 18,
         'year': 2010,
         'author': 'Albert Lukaszewski'},
        {'name': 'OpenCV Computer Vision with Python',
         'price': 35,
         'year': 2013,
         'author': 'Joseph Howse'},
        {'name': 'Python Data Visualization Cookbook',
         'price': 35,
         'year': 2013,
         'author': 'Igor Milovanovic'},
        {'name': 'Python Pocket Reference, 5th Edition',
         'price': 50,
         'year': 2014,
         'author': 'Mark Lutz'},
        {'name': 'Django 1.0 Template Development',
         'price': 24,
         'year': 2008,
         'author': 'Scott Newman'},
        {'name': 'Learning Django Web Development',
         'price': 42,
         'year': 2015,
         'author': 'Sanjeev Jaiswal, Ratan Kumar'},
        {'name': 'Django By Example',
         'price': 28,
         'year': 2015,
         'author': 'Antonio Mele'},
]

for book in books:
    print('inserting record [name=%s]' % book['name'])
    Book.objects.create(
            name=book['name'], price=book['price'],
            year=book['year'], author=book['author']
    )
